def solve(nums, k):
    widows = []
    for i, num in enumerate(nums):
        if num in widows:
            return True
        widows.append(num)
        if i >= k:
            widows.remove(nums[i - k])

    return False


if __name__ == "__main__":
    nums = [1, 2, 3, 1]
    k = 3
    print(solve(nums, k))
